package com.jon.experiment3.Controller;

import com.jon.experiment3.Dto.RegionStatus;
import com.jon.experiment3.Service.covidTrackService;
import com.sun.jdi.IntegerType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * author 陈伯瑞
 * date 2020/5/8 0008 14:52
 * version 1.0
 **/
@Controller
public class RegionController {
    /**
     *全球国家地区病例数据
     */
    @Autowired
    private covidTrackService covidTrackService;

    @GetMapping("/")
    public ModelAndView getALLRegions(Map<String, Object> map)  {

        List<RegionStatus> statuses=covidTrackService.getLastStatesData();
        Integer gogalData= 0;
        Integer addData= 0;
        for(RegionStatus status:statuses){
            gogalData+=status.getLatestTotalCases();
            addData+=status.getLatestPreTotalCases();
        }
        addData=gogalData-addData;
        map.put("statuses",statuses);
        map.put("gogalData",gogalData);
        map.put("addData",addData);
        return new ModelAndView("index",map);
    }
    @GetMapping("/byCountry")
    public ModelAndView getByRegions(String country, Map<String, Object> map) throws IOException {

        List<RegionStatus> statuses=covidTrackService.getLastStatesDataByStates(country);
        List<RegionStatus> statusesAll=covidTrackService.getLastStatesData();
        Integer gogalData= 0;
        Integer addData= 0;
        for(RegionStatus statusAll:statusesAll){
            gogalData+=statusAll.getLatestTotalCases();
            addData+=statusAll.getLatestPreTotalCases();
        }
        addData=gogalData-addData;
        map.put("statuses",statuses);
        map.put("gogalData",gogalData);
        map.put("addData",addData);
        return new ModelAndView("index",map);
    }
}
